<template>
  <div class="gwrapper" ref="gwrapper">
    <div class="gscroll" ref="gscroll">
      <div class="item-list">
        <div class="item" v-for="(item, index) of galleryLists" :key="item.id">
          <img v-lazy="item.imgUrl" alt="画廊图片" />
          <div class="page">
            {{ index + 1 + "/" + galleryLists.length }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import BScroll from "better-scroll";
import ObserveDom from "@better-scroll/observe-dom";
BScroll.use(ObserveDom);
export default {
  name: "gallery",
  props: {
    galleryLists: Array,
  },
  mounted() {
    this.scroll = new BScroll(this.$refs.gwrapper, {
      startX: 0,
      click: true,
      scrollX: true,
      scrollY: false,
      eventPassthrough: "vertical",
      observeDOM: true,
    });
  },
  methods: {},
};
</script>
<style lang="scss" scoped>
.gwrapper {
  width: 100vw;
  .gscroll {
    width: 20rem;
    margin-top: 0.2rem;
    margin-bottom: -0.2rem;
    white-space: nowrap;
    height: $galleryHeight;
    .item-list {
      height: $galleryHeight;
      .item {
        position: relative;
        margin-left: 0.2rem;
        font-size: $subTitleFontSize;
        text-align: center;
        line-height: 0.5rem;
        height: $galleryHeight;
        display: inline-block;
        & img {
          border-radius: 0.1rem;

          width: $galleryWidth;
        }
        & img[lazy="loading"] {
          width: 1rem;
          height: 1rem;
        }
        & .page {
          position: absolute;
          padding: 0 0.1rem;
          color: white;
          top: 0.1rem;
          line-height: 0.4rem;
          border-radius: 30%;
          background: rgba(0, 0, 0, 0.3);
          right: 0.1rem;
        }
      }
    }
  }
}
</style>